package io.kiki.sba.registry.server.clientInterface.strategy.impl;

import io.kiki.sba.registry.api.exchange.RequestChannelClosedException;
import io.kiki.sba.registry.core.model.BaseRegister;
import io.kiki.sba.registry.core.model.RegisterResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public final class RegisterLogs {
    public static final Logger logger = LoggerFactory.getLogger(RegisterLogs.class);

    private RegisterLogs() {
    }

    public static void logError(BaseRegister register, String name, RegisterResponse registerResponse, Throwable e) {
        if (e instanceof RequestChannelClosedException) {
            logger.warn("{} register error, Type {}, {}", name, register.getEventType(), e.getMessage());
        } else {
            logger.error("{} register error, Type {}", name, register.getEventType(), e);
        }
        registerResponse.setSuccess(false);
        registerResponse.setMessage(name + " register failed!Type:" + register.getEventType());
    }
}
